package com.oscar.ehome.view.pageview.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.oscar.ehome.R;
import com.oscar.ehome.base.C;
import com.oscar.ehome.bean.pagebean.HuokeBean;
import com.oscar.ehome.provider.gildeimage.GildeUtils;
import com.oscar.ehome.utils.system.SystemConfigFactory;
import com.oscar.ehome.utils.util.CommonUtils;
import com.oscar.ehome.utils.util.DateUtil;
import com.oscar.ehome.view.pageview.HuokeListActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by juxing
 * author: MengWanhe
 * date: On 2017/10/12
 */

public class HuokeListAdapter extends BaseAdapter {

    private List<HuokeBean.HuokeListBean> list = new ArrayList<>();
    private LayoutInflater mInflater;
    private Context mContext = null;
    HuokeBean.HuokeListBean bean;


    public HuokeListAdapter(Context context, List<HuokeBean.HuokeListBean> list) {
        this.mContext = context;
        this.list = list;
        mInflater = LayoutInflater.from(context);
    }

    public void setLists(List<HuokeBean.HuokeListBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.adapter_huoke, null);
            holder = new ViewHolder();
            holder.huoke_title = (TextView) convertView.findViewById(R.id.huoke_title);
            holder.huoke_types = (ImageView) convertView.findViewById(R.id.huoke_types);
            holder.huoke_action_time = (TextView) convertView.findViewById(R.id.huoke_action_time);
            holder.huoke_end_time = (TextView) convertView.findViewById(R.id.huoke_end_time);
            holder.huoke_img = (ImageView) convertView.findViewById(R.id.huoke_img);
            convertView.setTag(holder); //
        } else {
            holder = (ViewHolder) convertView.getTag(); //
        }

        if (list.size() > 0) {
            bean = list.get(position);
            if (bean != null) {
                holder.huoke_title.setText(bean.getGamesTheme());
                if (bean.getGamesBigimg() != null && !"".equals(bean.getGamesBigimg())) {
                    GildeUtils.loadUrlImages(C.qiniu_ip + bean.getGamesBigimg(), holder.huoke_img, mContext);
                } else {
                    holder.huoke_img.setImageResource(R.mipmap.huokea);
                }
                if (bean.getIsEnd().equals("0")) {
//                    holder.huoke_types.setText("进行中");
                    holder.huoke_types.setImageResource(R.mipmap.bianjiaojxz);
                } else if (bean.getIsEnd().equals("1")) {
//                    holder.huoke_types.setText("已过期");
                    holder.huoke_types.setImageResource(R.mipmap.bianjiaoyjs);
                }
                if (bean.getBeginTime() != null && !bean.getBeginTime().equals("")) {
                    holder.huoke_action_time.setText(DateUtil.strToDate(bean.getBeginTime()));
                }
                if (bean.getEndTime() != null && !bean.getEndTime().equals("")) {
                    holder.huoke_end_time.setText(DateUtil.strToDate(bean.getEndTime()));
                }
            }
        }

        return convertView;
    }

    class ViewHolder {
        TextView huoke_title;//
        ImageView huoke_types;//
        TextView huoke_action_time;//
        TextView huoke_end_time;//
        ImageView huoke_img;
    }

}
